package demo;

import java.util.HashMap;
import java.util.Map;

/**
 * 2数之和
 */
class Solution7 {
	public int[] twoSum(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < nums.length; i++) {
			map.put(nums[i], i);
		}
		for (int i = 0; i < nums.length; i++) {
			int other = target - nums[i];
			if (map.containsKey(other) && i != map.get(other)) {
				return new int[] {i, map.get(other)};
			}
		}
		return new int[]{-1, -1};
	}
}

